package com.dy.design_pattern_study.visitor_pattern.dome2;

import java.util.ArrayList;
import java.util.List;

/**
 * @CreateBy zhangdingyi
 * @Date 2023-04-25
 * @Content 对象结构
 */
public class ObjectStructure {
    private List<Person> elements = new ArrayList<>();

    //增加
    public void attach(Person element) {
        elements.add(element);
    }

    //移除
    public void detach(Person element) {
        elements.remove(element);
    }

    //显示
    public void display(Action visitor) {
        for (Person person : elements) {
            //二次分派
            person.accept(visitor);
        }
    }

}


